package com.cskaoyan.service;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author gatsby
 * @since 2022/10/15 11:26
 */
@Service
public class WxFeedBackServiceImpl implements WxFeedBackService {

    @Autowired
    MarketFeedbackMapper marketFeedbackMapper;
    /**
     * 提交反馈的业务逻辑
     *
     * @param marketFeedback
     * @return void
     * @author gatsby
     * @since 2022/10/15 11:32
     */
    @Transactional
    @Override
    public void submit(MarketFeedback marketFeedback) {
        //获取用户id
        MarketUser marketUser = (MarketUser)SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        Integer userId = marketUser.getId();
        //获取用户的用户名
        String username = marketUser.getUsername();
        marketFeedback.setDeleted(false);
        marketFeedback.setUserId(userId);
        marketFeedback.setUsername(username);
        marketFeedback.setAddTime(new Date());
        marketFeedback.setUpdateTime(new Date());
        //插入到数据库中
        marketFeedbackMapper.insertSelective(marketFeedback);

    }
}
